﻿using System.Collections.Generic;

namespace KuiHuaBaoDian.Services.Battle.Entity {

    /// <summary>
    /// 实体状态
    /// </summary>
    public readonly struct BattleEntityState {

        /// <summary>
        /// 未知
        /// </summary>
        public static readonly BattleEntityState Unknown = new() { Value = 0 };

        /// <summary>
        /// 空闲
        /// </summary>
        public static readonly BattleEntityState Idle = new() { Value = 1 };

        /// <summary>
        /// 移动
        /// </summary>
        public static readonly BattleEntityState Move = new() { Value = 2 };

        /// <summary>
        /// 攻击
        /// </summary>
        public static readonly BattleEntityState Attack = new() { Value = 3 };

        /// <summary>
        /// 死亡
        /// </summary>
        public static readonly BattleEntityState Die = new() { Value = 4 };

        private static readonly IReadOnlyDictionary<BattleEntityState, string> NAME_DICTIONARY = new Dictionary<BattleEntityState, string> {
            { Unknown, nameof(Unknown) },
            { Idle, nameof(Idle) },
            { Move, nameof(Move) },
            { Attack, nameof(Attack) },
            { Die, nameof(Die) },
        };

        /// <summary>
        /// 值
        /// </summary>
        public int Value { get; init; }

        public override bool Equals(object obj) {
            if (obj is BattleEntityState other) {
                return other.Value == Value;
            }
            return false;
        }

        public override int GetHashCode() => Value.GetHashCode();

        public static bool operator ==(BattleEntityState left, BattleEntityState right) => left.Equals(right);

        public static bool operator !=(BattleEntityState left, BattleEntityState right) => !left.Equals(right);

        public override string ToString() {
            if (NAME_DICTIONARY.TryGetValue(this, out var name)) {
                return name;
            } else {
                return $"{nameof(BattleEntityState)}({Value})";
            }
        }
    }
}
